package com.joshjung.collections
{

    /**
     *
     * @author jjung
     */
    public class LLIterator
    {
        //---------------------------------------------------------------------
        //
        //  Variables
        //
        //---------------------------------------------------------------------
        protected var cur : LLElement;
        protected var beforeFirst : LLElement;
        protected var ll : LinkedList;

        //---------------------------------------------------------------------
        //
        //  Constructor
        //
        //---------------------------------------------------------------------
        /**
         *  Constructor
         */
        public function LLIterator(ll : LinkedList)
        {
            this.ll = ll;
            cur = beforeFirst = new LLElement(null, null, null);
        }

        //---------------------------------------------------------------------
        //
        //  Methods
        //
        //---------------------------------------------------------------------
        public function next() : *
        {
            if (cur == beforeFirst)
            {
                cur = ll.tail;

                if (cur)
                {
                    return cur.data;
                }
            }
            if (cur)
            {
                cur = cur.next;
            }

            if (cur)
            {
                return cur.data;
            }

            return null;
        }
    }
}
